

window.onload = function () {

    var indexbtn = document.querySelector(`.logo-c`)
    indexbtn.onclick = function () {
    location.href = "index.html"
}


    

var registerbtn = document.querySelector(`.register-button-box`)
registerbtn.onclick = function(){
    // console.log(111)
    var  username = document.querySelector(`[name="tel"]`).value;
    var  password = document.querySelector(`[name="password"]`).value;
    var  repass = document.querySelector(`[name="repass"]`).value;
    var check = document.querySelector(`.check`)
    console.log(username)

    var reg = /^1[3-9]\d{9}$/
    if(!reg.test(username)){
        alert(`用户名不规范`)
        return false
    }
    if(password ===``){
        alert(`密码不规范`)
        return false

    }
    if(password != repass){
    alert(`两次密码不一致`)
    return false}
    if(!check.checked){
        alert(`请勾选协议`)
        return false    }
var  xhr =new XMLHttpRequest;
xhr.open(`post`,`/register`)
xhr.setRequestHeader(`content-type`,`application/x-www-form-urlencoded`)
xhr.send(`username=${username}&password=${password}`)
xhr.onreadystatechange = function(){
    if(xhr.readyState === 4){
        if(xhr.status>=200 && xhr.status<300){
            var res = xhr.responseText;
            console.log(res);
            res =JSON.parse(res)
            if(res.code ==1){
                alert(res.msg)
                location.href = "login.html"
            }
            }
        }
    }
}


         

    


}
